package com.flyoil.petromp.ui.activity.activity_course;

import android.content.Intent;
import android.view.View;

import com.flyoil.petromp.R;
import com.flyoil.petromp.adapter.adapter_course.ItemCourseCertainAdapter;
import com.flyoil.petromp.base.BaseActivity;
import com.flyoil.petromp.base.BaseRecyAdapter;
import com.flyoil.petromp.entity.entity_course_list.CourseCertainEntity;
import com.flyoil.petromp.mvp_p.SearchCertainPresenter.SearchCertainPresenter;
import com.flyoil.petromp.mvp_v.ListUIView.BaseUIView;
import com.flyoil.petromp.ui.activity.activity_matter.OrderMessageActivity;
import com.flyoil.petromp.utils.Dialog.DialogHintUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 搜索具体的某一项流程数据
 */
public class SearchCourseCertainDataActivity extends BaseActivity implements BaseUIView {
    private ItemCourseCertainAdapter adapter;
    private String order_type;
    private SearchCertainPresenter presenter;
    private List<String> data_edt;

    @Override
    protected int getContentViewResId() {
        return R.layout.activity_search_course_certain_data;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setTextTitleName("搜索结果");
        adapter = new ItemCourseCertainAdapter(mContext);
        recyclerView = $(R.id.list_search_course_certain_data);
        setRecyviewLayoutManager(null);
        recyclerView.setAdapter(adapter);
        order_type = getIntent().getStringExtra("order_type");
        if (order_type == null) {
            order_type = "1";
        }
        data_edt = getIntent().getStringArrayListExtra("data_edt");
        if (data_edt == null) {
            data_edt = new ArrayList<>();
        }
        setTitleFromStatus();
        presenter = new SearchCertainPresenter(this, order_type);
    }

    /**
     * 根据状态显示
     */
    private void setTitleFromStatus() {
        switch (getIntent().getIntExtra("order_status", 0)) {
            case 0:
                setTextTitleName("搜索结果(已完成)");
                break;
            case 1:
                setTextTitleName("搜索结果(流转中)");
                break;
            case 2:
                setTextTitleName("搜索结果(草稿箱)");
                break;
            case 3:
                setTextTitleName("搜索结果(撤销)");
                break;
        }
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        setBackOnclickListner(mContext);
        adapter.setOnItemClickListener(onItemClickListener);
    }

    private BaseRecyAdapter.OnItemClickListener onItemClickListener = new BaseRecyAdapter.OnItemClickListener() {
        @Override
        public void Onclick(int position, Object data) {
            if(getIntent().getIntExtra("order_status", 0)==2){
                show_hint_dialog();
                return;
            }
            CourseCertainEntity entity = (CourseCertainEntity) data;
            Intent intent = new Intent(mContext, OrderMessageActivity.class);
            intent.putExtra("order_type", entity.getType());
            intent.putExtra("id", entity.getId());
            startActivity(intent);
        }
    };
    /**
     * 显示提示用户登录电脑端进行操作的弹框
     */
    private void show_hint_dialog() {
        DialogHintUtil.show_hint_message_diolog(mContext);
        DialogHintUtil.set_dialog_content("请登录电脑端填写表单详情");
        DialogHintUtil.set_dialog_cancle(null);
        DialogHintUtil.set_dialog_confirm("确定");
        DialogHintUtil.set_confirm_onclicklistener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogHintUtil.dismiss_dialog();
            }
        });
    }
    @Override
    protected void initdatas() {
        super.initdatas();
        presenter.initOrderStatus(getIntent().getIntExtra("order_status", 0));
        presenter.initNetworkData(data_edt);
    }

    @Override
    public void updataToUI(List data) {
        if (data != null) {
            if (data.size() == 0) {
                onDataNull(null);
            } else {
                onDataSucceed();
            }
            adapter.addBottonDatas(data);
            recyclerView.notifyDataSetChanged();
        } else {
            onDataError(null);
        }

    }
}
